#include "Projectile.h"
#include <new>
#include "Renderer.h"

Projectile::Projectile(GameObject* owner, int x, int y)
{
	m_objectType = OBJECT_TYPE::PROJECTILE;
	m_owner = owner;
	m_speed = 6;
	Position& pos = GetPosition();
	pos.x = x;
	pos.y = y;
	pos.width = 5;
	pos.height = 20;
}
Projectile::Projectile(long long id, GameObject* owner, int x, int y)
{
	m_objectType = OBJECT_TYPE::PROJECTILE;
	m_objectID = id;
	m_owner = owner;
	m_speed = 6;
	Position& pos = GetPosition();
	pos.x = x;
	pos.y = y;
	pos.width = 5;
	pos.height = 20;
}
Projectile::~Projectile(void)
{

}
void Projectile::DestroyData(void)
{

}
void Projectile::Copy(void* address)
{
	new (address) Projectile(*this);
}
void Projectile::Update(void)
{
	GetPosition().y -= m_speed;
}
void Projectile::Draw(void)
{
	Renderer::GetInstance().DrawObject(*this);
}
int Projectile::GetObjSize(void)
{
	return sizeof(*this);
}
SDL_Texture* Projectile::GetTexture(void)
{
	static SDL_Texture* texture = 0;
	if (!texture)
	{
		texture = Renderer::GetInstance().LoadTexture("c:/test.bmp");
	}
	return texture;
}
bool Projectile::Collides(GameObject* other)
{
	Position& myPos = GetPosition();
	Position& otherPos = other->GetPosition();
	if (  (((otherPos.x + otherPos.width ) >  myPos.x) && (otherPos.x < (myPos.x + myPos.width))) && ( ((otherPos.y + otherPos.height) > myPos.y) && (otherPos.y < (myPos.y + myPos.height) )))
		return true;
	return false;
}
GameObject* Projectile::GetOwner(void)
{
	return m_owner;
}